var express = require('express');
var fs = require('fs');
var router = express.Router();



/*
数据解释：
"Date": 日期
"Idle Containership Capacity (% of the fleet)": 空闲集装箱船容量
"Containership (12,000 + TEU) Contracting": 集装箱船合同
"China Seaborne Containerisable Exports": 中国海运可用集装箱装运出口量
"Containership (8,000 + TEU) Contracting": 集装箱船合同
"Total Containership Demolition": 集装箱船的毁坏总量
"exchange rate": 汇率
"CCFI": 中国集装箱运价指数
*/

/* there are some APIs. */
router.get('/', function(req, res, next) {
	var jsondata = JSON.parse(fs.readFileSync(process.cwd()+'/CFI.json'));
	res.send(jsondata);
	//console.log(jsondata);
});

router.post('/', function(req, res, next) {
	var jsondata = JSON.parse(fs.readFileSync(process.cwd()+'/CFI.json'));
	var resultData = [];
	for(var i = 0;i<jsondata.length;i++){
		if(req.body.sDate <= jsondata[i].Date && req.body.eDate >= jsondata[i].Date){
			resultData.push(jsondata[i]);
		}
	}
	res.json(resultData);
});

module.exports = router;
